<?php

if (!defined('BASEPATH'))
    exit('Tidak Diperkenankan mengakses langsung');
/* Class  Model : paket
 * di Buat oleh Diar PHP Generator
 * Update List untuk grid karena program generatorku lom sempurna ya hehehehehe */

class modelpaket extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function getArrayListpaket() { /* spertinya perlu lock table */
        $xBuffResul = array();
        $xStr = "SELECT " .
                "idx," .
                "namapaket," .
                "harga," .
                "date_mulai," .
                "date_akhir," .
                "idpegawai" .
                " FROM paket   order by idx ASC ";
        $query = $this->db->query($xStr);
        $xBuffResul['0'] = '-';
        foreach ($query->result() as $row) {
            $xBuffResul[$row->idx] = $row->namapaket;
        }
        return $xBuffResul;
    }

    function getListpaket($xAwal, $xLimit, $xSearch = '') {
        if (!empty($xSearch)) {
            $xSearch = "Where namapaket like '%" . $xSearch . "%'";
        }
        $xStr = "SELECT " .
                "idx," .
                "namapaket," .
                "harga," .
                "date_mulai," .
                "date_akhir," .
                "idpegawai" .
                " FROM paket $xSearch order by idx DESC limit " . $xAwal . "," . $xLimit;
        $query = $this->db->query($xStr);
        return $query;
    }

    function getDetailpaket($xidx) {
        $xStr = "SELECT " .
                "idx," .
                "namapaket," .
                "harga," .
                "date_mulai," .
                "date_akhir," .
                "idpegawai" .
                " FROM paket  WHERE idx = '" . $xidx . "'";
  
        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    function getLastIndexpaket() { /* spertinya perlu lock table */
        $xStr = "SELECT " .
                "idx," .
                "namapaket," .
                "harga," .
                "date_mulai," .
                "date_akhir," .
                "idpegawai" .
                " FROM paket order by idx DESC limit 1 ";
        $query = $this->db->query($xStr);
        $row = $query->row();
        return $row;
    }

    Function setInsertpaket($xidx, $xnamapaket, $xharga, $xdate_mulai, $xdate_akhir, $xidpegawai) {
        $xStr = " INSERT INTO paket( " .
                "idx," .
                "namapaket," .
                "harga," .
                "date_mulai," .
                "date_akhir," .
                "idpegawai) VALUES('" . $xidx . "','" . $xnamapaket . "','" . $xharga . "','" . $xdate_mulai . "','" . $xdate_akhir . "','" . $xidpegawai . "')";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    Function setUpdatepaket($xidx, $xnamapaket, $xharga, $xdate_mulai, $xdate_akhir, $xidpegawai) {
        $xStr = " UPDATE paket SET " .
                "idx='" . $xidx . "'," .
                "namapaket='" . $xnamapaket . "'," .
                "harga='" . $xharga . "'," .
                "date_mulai='" . $xdate_mulai . "'," .
                "date_akhir='" . $xdate_akhir . "'," .
                "idpegawai='" . $xidpegawai . "' WHERE idx = '" . $xidx . "'";
        $query = $this->db->query($xStr);
        return $xidx;
    }

    function setDeletepaket($xidx) {
        $xStr = " DELETE FROM paket WHERE paket.idx = '" . $xidx . "'";

        $query = $this->db->query($xStr);
        $this->setInsertLogDeletepaket($xidx);
    }

    function setInsertLogDeletepaket($xidx) {
        $xidpegawai = $this->session->userdata('idpegawai');
        $xStr = "insert into logdelrecord(idxhapus,nmtable,tgllog,ideksekusi) values($xidx,'paket',now(),$xidpegawai)";
        $query = $this->db->query($xStr);
    }

}

?>